Skip to content

Fix #4063: 修复游戏版本列表去重问题#4066

Merged
Glavo merged 3 commits intoHMCL-dev:mainfrom
Wulian233:version
Jul 26, 2025
Merged

Fix #4063: 修复游戏版本列表去重问题#4066
Glavo merged 3 commits intoHMCL-dev:mainfrom
Wulian233:version

Conversation

@Wulian233
Copy link
Copy Markdown
Contributor

@Wulian233 Wulian233 commented Jul 5, 2025

被吞的版本共同点是 有发布时间一致的另一个版本
查阅源码发现内部是使用 TreeSet 基于发布时间 比较版本、排序

屏幕截图 2025-07-05 084714

return dateCompare;
}

return GameVersionNumber.asGameVersion(getSelfVersion()).compareTo(o.getSelfVersion());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return GameVersionNumber.asGameVersion(getSelfVersion())
    .compareTo(GameVersionNumber.asGameVersion(o.getSelfVersion()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接 GameVersionNumber.compare(getSelfVersion(), o.getSelfVersion()) 就可以了

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接 GameVersionNumber.compare(getSelfVersion(), o.getSelfVersion()) 就可以了

thanks❤️

@Glavo Glavo requested a review from Copilot July 26, 2025 18:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a deduplication issue in the game version list where versions with identical release dates were being incorrectly removed. The fix modifies the comparison logic to use version numbers as a secondary comparison criteria when release dates are equal.

  • Modified the compareTo method in GameRemoteVersion to include version number comparison as a tiebreaker
  • Added import for GameVersionNumber utility class to support the enhanced comparison logic

Comment on lines +60 to +65
int dateCompare = o.getReleaseDate().compareTo(getReleaseDate());
if (dateCompare != 0) {
return dateCompare;
}

return GameVersionNumber.compare(getSelfVersion(), o.getSelfVersion());
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method call o.getSelfVersion() assumes that the cast to GameRemoteVersion is safe, but the type check only verifies instanceof GameRemoteVersion. If o is not actually a GameRemoteVersion, this will cause a ClassCastException. Consider casting o to GameRemoteVersion explicitly after the instanceof check.

Suggested change
int dateCompare = o.getReleaseDate().compareTo(getReleaseDate());
if (dateCompare != 0) {
return dateCompare;
}
return GameVersionNumber.compare(getSelfVersion(), o.getSelfVersion());
GameRemoteVersion gameRemoteVersion = (GameRemoteVersion) o;
int dateCompare = gameRemoteVersion.getReleaseDate().compareTo(getReleaseDate());
if (dateCompare != 0) {
return dateCompare;
}
return GameVersionNumber.compare(getSelfVersion(), gameRemoteVersion.getSelfVersion());

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit 27361c6 into HMCL-dev:main Jul 26, 2025
2 checks passed
@Wulian233 Wulian233 deleted the version branch July 26, 2025 19:15
Glavo added a commit that referenced this pull request Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants